package com.easyadmin.pro.modules.sys.controller;

import com.easyadmin.pro.common.constants.HttpConstants;
import com.easyadmin.pro.common.controller.BaseController;
import com.easyadmin.pro.common.vo.RestResult;
import com.easyadmin.pro.modules.sys.vo.RoleRelevanceRouterVo;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.easyadmin.pro.modules.sys.entity.UserPermissionsEntity;
import com.easyadmin.pro.modules.sys.service.IUserPermissionsService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author xulin
 * @since 2024-04-02
 */
@RestController
@RequestMapping(HttpConstants.SYS_MODULE_PATH + "/userPermissions/")
public class UserPermissionsController extends BaseController {

    @Autowired
    private IUserPermissionsService iUserPermissionsService;

    /**
     * 添加。
     *
     * @param userPermissionsEntity 
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    public RestResult save(@RequestBody UserPermissionsEntity userPermissionsEntity) {
        return success(iUserPermissionsService.save(userPermissionsEntity));
    }

    /**
     * 批量添加
     * @param userPermissionsEntities
     * @return
     */
    @PostMapping("saveBatch")
    public RestResult saveBatch(@RequestBody List<UserPermissionsEntity> userPermissionsEntities) {
        return success(iUserPermissionsService.saveBatch(userPermissionsEntities));
    }

    /**
     * 根据主键删除。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    public RestResult remove(@PathVariable Serializable id) {
        return success(iUserPermissionsService.removeById(id));
    }

    /**
     * 根据主键更新。
     *
     * @param userPermissionsEntity 
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    public RestResult update(@RequestBody UserPermissionsEntity userPermissionsEntity) {
        return success(iUserPermissionsService.updateById(userPermissionsEntity));
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    public RestResult list() {
        return success(iUserPermissionsService.list());
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    public RestResult getInfo(@PathVariable Serializable id) {
        return success(iUserPermissionsService.getById(id));
    }

    /**
     * 分页查询。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    public RestResult page(Page<UserPermissionsEntity> page) {
        return success(iUserPermissionsService.page(page));
    }


    /**
     * 角色关联路由
     * @param roleRelevanceRouterVo
     * @return
     */
    @PostMapping("changeRoleRouter")
    public RestResult changeRoleRouter(@RequestBody RoleRelevanceRouterVo roleRelevanceRouterVo) {
        iUserPermissionsService.changeRoleRouter(roleRelevanceRouterVo);
        return success();
    }

}
